package wwl.lsf.jdk.dynamic;


import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import sun.misc.ProxyGenerator;
import wwl.lsf.Dao;

public class Dynamic implements InvocationHandler {

  public static void main(String[] args) throws Exception {
    Dynamic dynamic = new Dynamic();
    Dao o = (Dao) Proxy
        .newProxyInstance(dynamic.getClass().getClassLoader(), new Class[]{Dao.class}, dynamic);
    o.query();
    byte[] lsfs = ProxyGenerator.generateProxyClass("lsf", new Class[]{Dao.class});
    FileOutputStream outputStream = new FileOutputStream("C://lsf.class");
    outputStream.write(lsfs);
    outputStream.flush();
    outputStream.close();

  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    System.out.println("jdk的动态代理");
    return null;
  }
}
